package biz.manager;

import java.util.Collection;

import models.Manager;
import utils.TransactionTemplate;
import dao.ManagerDao;
import dao.ManagerDaoHbnImpl;

public class ManagerBizImpl implements ManagerBiz {
	private ManagerDao managerDao=new ManagerDaoHbnImpl();
	@Override
	public void addManager(Manager mag) {
		try {
			TransactionTemplate.beginTransaction();
			managerDao.addManager(mag);
			TransactionTemplate.commit();
		} catch (Exception e) {
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
	}

	@Override
	public void delManagerById(Long magId) {
		try {
			TransactionTemplate.beginTransaction();
			managerDao.delManagerById(magId);
			TransactionTemplate.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
	}

	@Override
	public Collection<Manager> selAllManager() {
		Collection<Manager> mags=null;
		try {
			TransactionTemplate.beginTransaction();
			mags = managerDao.selAllManager();
			TransactionTemplate.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
		return mags;
	}

	@Override
	public Manager selManagerById(Long magId) {
		Manager mag=null;
		try {
			TransactionTemplate.beginTransaction();
			mag = managerDao.selManagerById(magId);
			TransactionTemplate.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
		return mag;
	}

	@Override
	public void updateManager(Manager mag) {
		try {
			TransactionTemplate.beginTransaction();
			managerDao.updateManager(mag);
			TransactionTemplate.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			TransactionTemplate.rollback();
		}
	}

}
